import baseurl1 from './baseurl1.js'
let ajaxnum=0
const http1 = (options={})=>{
    ajaxnum++
    wx.showLoading({title:'加载中...',mask:true});
  return new Promise((reslove,reject)=>{
    console.log(options,'5555555555555');
    let tokenInfo = null
    if (wx.getStorageSync('token')) {
        tokenInfo = JSON.parse(wx.getStorageSync('token'))
    } else if (wx.getStorageSync('studentToken')) {
        tokenInfo = JSON.parse(wx.getStorageSync('studentToken'))
    }
    if (options.url == '/getSelectScoreType') {
        tokenInfo = JSON.parse(wx.getStorageSync('studentToken'))
    }
    console.log(tokenInfo, '1111111');
    if (tokenInfo) {
        options.header.Authorization = tokenInfo.authorization
        options.header.uid = tokenInfo.id
    }
    wx.request({
      url:baseurl1.baseUrl1+options.url,//服务器地址
      method:options.method || 'get',
      data:options.data || {},
      header:options.header || {"content-type":"application/x-www-form-urlencoded"},
      timeout:options.timeout || 60000,
      success(res){
        if (res.data.msg == '权限不足') {
            wx.showToast({
				title: '登陆超时，请重新登陆!',
				icon:"none"
			})
            wx.navigateTo({
                url: '/pages/newteacherlogin/newteacherlogin', // 需要跳转的页面路径
            });
        }
        reslove(res)
      },
      fail(err){
        wx.showModal({
            title: '系统升级中',
            content: '系统升级中,请稍后重试',
        })
        reject(err)
      },
        complete:()=>{
            ajaxnum--
            if(ajaxnum===0){
                wx.hideLoading();
            }
        }
    })
  })
}
export default http1